import request from '@/utils/processRequest';
import axios from 'axios';
import p from '@/utils/processRequest1';
const ENV = process.env.NODE_ENV;

export function getTable(data, url) {
  return request({
    url,
    method: 'post',
    data
  });
}

export function getCommonDataSource(data, url, method = 'post') {
  const requestData = {
    url,
    method,
    baseUrl: 'http://10.10.10.22:8888/'
  };

  if (method === 'post') {
    requestData.data = data;
  } else {
    requestData.params = data;
  }

  return request(requestData);
}

/**
 *
 *
 * @export
 * @param {*} focusUrlParams
 * @param {*} url
 * @return {*}
 */
export async function getCommonData(focusUrlParams, url, headers = {}) {
  const { method, data, params } = focusUrlParams;
  let url1 = url;
  if (ENV === 'development') {
    if (!url1.startsWith('http')) {
      const { url: configUrl } = await p();
      const a = configUrl.split('/');
      a.pop();
      url1 = a.join('\/\/').replace('//', '') + url;
    }
  }
  const requestData = {
    url: url1,
    // url: 'http://115.239.175.246:5902/' + url,
    // method,
    headers: {
      Token: localStorage.getItem('xcToken'),
      ...headers
    },
    method,
    data,
    params
    // headers
  };
  // 等token问题解决就取正
  // if (requestData.headers) {
  //   requestData.headers = {
  //     'Token': localStorage.getItem('xcToken')
  //   };
  // }

  // if (method === 'post') {
  //   requestData.data = data;
  // } else if (method === 'get') {
  //   requestData.method = 'get';
  //   requestData.params = data;
  // }
  return axios(requestData);
}

